package com.assembler.app.debruij.succinct;

import java.util.Collections;
import java.util.List;

import com.assembler.app.debruij.model.Edge;
import com.assembler.app.debruij.model.Node;

/**
 * This abstract class provides the implementation of methods that don't depend on implementation of graph
 * like select() and rank().
 * 
 * This class is a part of the lab rotation project for PhD  students in January 2014.
 * School of Computing
 * National University Singapore.
 * 
 * @author Iana Pyrogova, Abha Belorkar
 * @version 1.0.1
 */
public abstract class AbstractGraph {

	/**
	 * Returns the number of occurences of symbol c on the closed range [0,i] in the sequenceL.
	 * @param i
	 * @param sequenceL
	 * @param c
	 * @return
	 */
	public int rank(int i, List<Boolean> sequenceL, Boolean c) {
		List<Boolean> subList = sequenceL.subList(0, i + 1);

		return Collections.frequency(subList, c);
	}

	/**
	 * Returns the number of occurences of symbol c on the closed range [0,i] in the sequenceEdge
	 * @param i
	 * @param sequenceEdge
	 * @param c
	 * @return
	 */
	public int rank(int i, List<Edge> sequenceEdge, Edge c) {
		List<Edge> subList = sequenceEdge.subList(0, i + 1);

		return Collections.frequency(subList, c);
	}

	
	/**
	 * Returns the number of occurences of symbol c on the closed range [0,i] in the sequence
	 * @param i
	 * @param sequence
	 * @param c
	 * @return
	 */
	public int rank(int i, List<Node> sequence, Node c) {
		List<Node> subList = sequence.subList(0, i + 1);

		return Collections.frequency(subList, c);
	}
	

	/**
	 * Returns the position of the ith occurence of symbol c in the sequence
	 * @param i
	 * @param sequence
	 * @param c
	 * @return
	 */
	public int select(int i, List<Node> sequence, Node c) {
		if (i <= 0) {
			return -1;
		}
		return sequence.indexOf(c) + i - 1;
	}

}
